<?php
final class mcz_Inflector
{
    /**
     *  Return an CamelizeSyntaxed (LikeThisDearReader) from something like_this_dear_reader.
     *
     * @param string $string Word to camelize
     * @return string Camelized word. LikeThis.
     */
    public static function camelize($string)
    {
        return str_replace(' ','',ucwords(str_replace('_',' ', $string)));
    }

    /**
     * Return an underscore_syntaxed (like_this_dear_reader) from something LikeThisDearReader.
     *
     * @param  string $string CamelCased word to be "underscorized"
     * @return string Underscored version of the $string
     */
    public static function underscore($string)
    {
        return strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $string));
    }

    /**
     * Return an Humanized syntaxed (Like this dear reader) from something like_this_dear_reader.
     *
     * @param  string $string CamelCased word to be "underscorized"
     * @return string Underscored version of the $string
     */
    public static function humanize($string)
    {
        return ucfirst(str_replace('_', ' ', $string));
    }

    public static function removeDiacritics($utf8String)
    {
        // strtr is not multibyte-aware so we have to decode to iso first
        // Important notice: this source code should be utf8 encoded
        return strtr(utf8_decode($utf8String),
                     utf8_decode(
                        'ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ'),
                        'AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn');
    }
    
    /**
     * Makes a clean file name from a string
     *
     * @param string "dirty" file name
     * @return string "clean" file name
     */
    public static function fileName($string)
    {
        $string = self::removeDiacritics($string);
        $string = strtolower($string);
        $string = preg_replace("/[^a-z0-9\\.\\-\\_]/i",'_',$string);
        return $string;
    }
}